package com.ruoyi.web.controller.afterSale;

import com.ruoyi.after_sale.domain.AfterSale;
import com.ruoyi.after_sale.service.IAfterSaleService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单售后Controller
 * 
 * @author 张富饶
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/after_sale/after_sale")
public class AfterSaleController extends BaseController
{
    @Autowired
    private IAfterSaleService afterSaleService;

    /**
     * 查询订单售后列表
     */
    @PreAuthorize("@ss.hasPermi('after_sale:after_sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(AfterSale afterSale)
    {
        startPage();
        List<AfterSale> list = afterSaleService.selectAfterSaleList(afterSale);
        return getDataTable(list);
    }

    /**
     * 导出订单售后列表
     */
    @PreAuthorize("@ss.hasPermi('after_sale:after_sale:export')")
    @Log(title = "订单售后", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfterSale afterSale)
    {
        List<AfterSale> list = afterSaleService.selectAfterSaleList(afterSale);
        ExcelUtil<AfterSale> util = new ExcelUtil<AfterSale>(AfterSale.class);
        util.exportExcel(response, list, "订单售后数据");
    }

    /**
     * 获取订单售后详细信息
     */
    @PreAuthorize("@ss.hasPermi('after_sale:after_sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(afterSaleService.selectAfterSaleById(id));
    }

    /**
     * 新增订单售后
     */
    @PreAuthorize("@ss.hasPermi('after_sale:after_sale:add')")
    @Log(title = "订单售后", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfterSale afterSale)
    {
        return toAjax(afterSaleService.insertAfterSale(afterSale));
    }

    /**
     * 修改订单售后
     */
    @PreAuthorize("@ss.hasPermi('after_sale:after_sale:edit')")
    @Log(title = "订单售后", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfterSale afterSale)
    {
        return toAjax(afterSaleService.updateAfterSale(afterSale));
    }

    /**
     * 删除订单售后
     */
    @PreAuthorize("@ss.hasPermi('after_sale:after_sale:remove')")
    @Log(title = "订单售后", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(afterSaleService.deleteAfterSaleByIds(ids));
    }
}
